use serde::Serialize;
use utoipa::ToSchema;

use crate::domain::entity::user::Model as UserModel;

#[derive(Clone, Debug, Default, Serialize, ToSchema)]
pub struct EditorLoadResponse {
    pub id: String,
    pub name: String,
    pub real_name: String,
    pub role_types: String,
    pub inner_types: String,
    pub gender: i16,
    pub phone_text: Option<String>,
    pub avatar_path: Option<String>,
    pub email_text: Option<String>,
    pub created_time: i64,
    pub is_authed: bool,
    pub is_enabled: bool,
}

#[derive(Clone, Debug, Default, Serialize, ToSchema)]
pub struct UserMasterResponse {
    pub id: String,
    pub editor: Option<EditorLoadResponse>,
    pub no: String,
    pub name: String,
    pub real_name: String,
    pub role_types: Option<String>,
    pub inner_types: Option<String>,
    pub gender_title: Option<String>,
    pub phone_title: Option<String>,
    pub avatar_path: Option<String>,
    pub email_title: Option<String>,
    pub last_login_time: Option<i64>,
    pub is_authed: bool,
    pub is_enabled: bool,
    pub created_time: i64,
    pub updated_time: i64,
    pub is_deleted: bool,
    pub deleted_time: Option<i64>,
}

impl From<UserModel> for UserMasterResponse {
    fn from(model: UserModel) -> Self {
        UserMasterResponse {
            id: model.id.to_string(),
            no: model.no.to_owned(),
            name: model.name.to_owned(),
            real_name: model.real_name.to_owned(),
            role_types: Some(model.role_types),
            inner_types: Some(model.inner_types),
            avatar_path: Some(model.avatar_path),
            is_authed: model.is_authed,
            is_enabled: model.is_enabled,
            created_time: model.created_time,
            updated_time: model.updated_time,
            is_deleted: model.is_deleted,
            deleted_time: model.deleted_time,
            ..Default::default()
        }
    }
}

#[derive(Clone, Debug, Default, Serialize, ToSchema)]
pub struct EditorListResponse {
    pub id: String,
    pub editor: Option<EditorLoadResponse>,
    pub no: String,
    pub name: String,
    pub real_name: String,
    pub role_types: Option<String>,
    pub inner_types: Option<String>,
    pub gender: i16,
    pub gender_title: i16,
    pub phone: Option<String>,
    pub phone_text: Option<String>,
    pub avatar_path: Option<String>,
    pub email: Option<String>,
    pub email_text: Option<String>,
    pub last_login_time: Option<i64>,
    pub is_authed: bool,
    pub is_enabled: bool,
    pub created_time: i64,
    pub updated_time: i64,
    pub is_deleted: bool,
    pub deleted_time: Option<i64>,
}
